// app  设置
import Cookies from 'js-cookie'

const state = {
    language: Cookies.get("language") ? Cookies.get("language") : 'zh',
    sidebar: {
        opend: Cookies.get("sidebarStatus") ? !!+Cookies.get('sidebarStatus') : true,
        withoutAnimation: false
    },
    // md5:MD5('2LgomkNkLoJgGu74T4'+Date.now()).toString(),
    md5:'2LgomkNkLoJgGu74T4',
    device: 'desktop',   //显示移动和pc  'mobile' 
}
const mutations = {
    // 显示左侧的导航
    TOGGLE_SIDEBAR: state => {
        state.sidebar.opend = !state.sidebar.opend
        state.sidebar.withoutAnimation = false
        if (state.sidebar.opend) {
            Cookies.set('sidebarStatus', 1)
        } else {
            Cookies.set('sidebarStatus', 0)
        }
    },
    // 关闭移动切换后的模态
    CLOSE_SIDEBAR: (state, withoutAnimation) => {
        Cookies.set('sidebarStatus', 0)
        state.sidebar.opend = false
        state.sidebar.withoutAnimation = withoutAnimation
    },
    // 切换移动和pc
    TOGGLE_DEVICE: (state, device) => {
        state.device = device
    },
     // 切换语言
     SET_LANGUAGE: (state, language) => {
        state.language = language
        Cookies.set('language', language)
    },
}
const actions = {
    toggleSideBar({ commit }) {
        commit('TOGGLE_SIDEBAR')
    },
    setLanguage({ commit }, language) {
        commit('SET_LANGUAGE', language)
    },
    closeSideBar({ commit }, { withoutAnimation }) {
        commit('CLOSE_SIDEBAR', withoutAnimation)
    },
    toggleDevice({ commit }, device) {
        commit('TOGGLE_DEVICE', device)
    },
}
export default {
    namespaced: true,
    state,
    mutations,
    actions

}